<style>
    .layui-form-label.required:before { /* 这种写法也可以*/
        content: ' *';
        color: red;
    }

    .open-form .layui-input-block{
        margin-left: 145px;
    }
    .open-form .layui-form-label {
        width: 115px;
    }

    .addProductionPlanForm-title .title, .examineProductionPlanForm-title .title {
        display: inline-block;
        margin: 20px;
        font-size: 16px;
        font-weight: bold;
        color: #333333;
        line-height: 19px;
        position: relative;
        padding: 6px 0 19px 0;
    }

    .addProductionPlanForm-title .title:after, .examineProductionPlanForm-title .title:after {
        content: '';
        display: block;
        position: absolute;
        left: 0;
        bottom: 0;
        width: calc(100% + 6px);
        height: 3px;
        background: #0A8B0A;
    }
</style>
<script type="text/javascript" src="../../../admin/assets/js/pdfobject.min.js"></script>
<!-- 表单弹窗 -->
<form lay-filter="requirePlanProductInfoFrom" class="layui-form open-form">
    <div class="open-model">
        <div class="open-auto">

            <div class="layui-form-item layui-row">


                <div class="layui-col-md3">
                    <label class="layui-form-label">材料编码：</label>
                    <div class="layui-input-block">
                        <input type="text" id="materialCode" name="materialCode" disabled class="layui-input"
                               placeholder="材料编码">
                    </div>
                </div>


                <div class="layui-col-md3">
                    <label class="layui-form-label">组件描述：</label>
                    <div class="layui-input-block">
                        <input type="text" id="materialDescribe" name="materialDescribe" disabled  class="layui-input"
                               placeholder="组件描述">
                    </div>
                </div>



                <div class="layui-col-md3">
                    <label class="layui-form-label">PlantCode：</label>
                    <div class="layui-input-block">
                        <input type="text" id="plantCode" name="plantCode" disabled class="layui-input"
                               placeholder="PlantCode">
                    </div>
                </div>

                <div class="layui-col-md3">
                    <label class="layui-form-label">工厂名称：</label>
                    <div class="layui-input-block">
                        <input type="text" id="factoryName" name="factoryName" disabled class="layui-input"
                               placeholder="工厂名称">
                    </div>
                </div>


            </div>



            <div class="layui-form-item layui-row">

                <div class="layui-col-md3">
                    <label class="layui-form-label">物料简码：</label>
                    <div class="layui-input-block">
                        <input type="text" id="materialSimplifiedCode" name="materialSimplifiedCode" disabled class="layui-input"
                               placeholder="物料简码">
                    </div>
                </div>
                <div class="layui-col-md3">
                    <label class="layui-form-label">生产线：</label>
                    <div class="layui-input-block">
                        <input type="text" id="productLine" name="productLine" disabled class="layui-input"
                               placeholder="生产线">
                    </div>
                </div>

                <div class="layui-col-md3">
                    <label class="layui-form-label">采购组织：</label>
                    <div class="layui-input-block">
                        <input type="text" id="purchaseTissue" name="purchaseTissue" disabled class="layui-input"
                               placeholder="采购组织">
                    </div>
                </div>

                <div class="layui-col-md3">
                    <label class="layui-form-label">需求数量：</label>
                    <div class="layui-input-block">
                        <input type="text" id="demandQuantity" name="demandQuantity"  disabled class="layui-input"
                               placeholder="需求数量">
                    </div>
                </div>

            </div>





            <div class="layui-form-item layui-row">

                <div class="layui-col-md3">
                    <label class="layui-form-label">单位：</label>
                    <div class="layui-input-block">
                        <input type="text" id="materialUnit" name="materialUnit" disabled class="layui-input"
                               placeholder="单位">
                    </div>
                </div>

                <div class="layui-col-md3">
                    <label class="layui-form-label">添加性质：</label>
                    <div class="layui-input-block">
                        <input type="text" id="saveSource" name="saveSource" disabled class="layui-input"
                               placeholder="添加性质">
                    </div>
                </div>

                <div class="layui-col-md3">
                    <label class="layui-form-label">更新人：</label>
                    <div class="layui-input-block">
                        <input type="text" id="modifierName" name="modifierName"  disabled class="layui-input"
                               placeholder="更新人">
                    </div>
                </div>


                <div class="layui-col-md3">
                    <label class="layui-form-label">更新时间：</label>
                    <div class="layui-input-block">
                        <input type="text" id="updateTime" name="updateTime" disabled class="layui-input"
                               placeholder="更新时间">
                    </div>
                </div>

            </div>



            <div class="examineProductionPlanForm-title">
                <h3 class="title">变动记录</h3>
            </div>
            <div class="layui-form-item layui-row">
                <div id="demandDay">
                    <table class="layui-table" id="requirePlanProductTable" lay-filter="requirePlanProductTable"></table>
                </div>
            </div>
        </div>

    </div>
</form>

<script type="text/html" id="viewAttachmentHtml">
    <div id="example1" style="height: 100%;"></div>
</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'laydate', 'admin', 'laytpl', 'upload', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var config = layui.config;
        var table = layui.table;
        var admin = layui.admin;
        var form = layui.form;
        var laydate = layui.laydate;

        let skuInfoObj = new Map()
        let planItemData = [];

        //初始化计划表
        table.render({
            elem: '#requirePlanProductTable',
            data: planItemData,
            page: true,
            id: 'requirePlanProductTable',
            cols: [[
                  {type: 'numbers', title: '序号', width: 80}
                , {field: 'requirePlanNumber', align: 'center', edit: 'text', title: '需求计划编码9999999'}
                , {field: 'containedMaterialCount', align: 'center', edit: 'text', title: '所含物料数'}
                , {field: 'remark', align: 'center', edit: 'text', title: '备注描述'}
                , {field: 'plantCode', title: 'plantCode', align: 'center'}
                , {field: 'factoryName', title: '工厂名称', align: 'center'}
                , {field: 'purchaseTissue', title: '采购组织', align: 'center'}
                , {field: 'purchaseTissueName', title: '组织名称', align: 'center'}
                , {field: 'receiveMouthDate', title: '计划接收月份', align: 'center', width: 150}
                , {field: 'saveSource', title: '添加性质', align: 'center'}
                , {field: 'demandQuantity', align: 'center', edit: 'text', title: '需求数量'}
                , {field: 'creatorName', title: '添加人', align: 'center'}
                , {field: 'createTime', title: '添加时间', align: 'center'}
            ]]
        });

        table.on('rowDouble(requirePlanProductTable)', function(obj) {
            let birthdayCell = $(obj.tr).find('.date-cell');
            laydate.render({
                elem: birthdayCell[0], // 绑定到生日单元格
                type: 'month', // 类型为月
                format: 'yyyy-MM', // 格式
                range: false, // 不允许选择范围
                done: function (value, date) {
                    obj.update({
                        planTime: value
                    });
                    // 重新加载表格数据
                    table.reload('planItemData', {
                        data: planItemData // 传入更新后的数据
                    });
                }
            });
            // 手动触发日期选择器
            birthdayCell.click();
        });

        //数据
        let tempData = admin.getTempData("requirePlanProductData");

        if( tempData&& tempData.id != null){

            admin.req('production/productionPlan/admin/requirePlanProduct/selectRequirePlanProductDetail', {id: tempData.id}, function (res) {
              
                if (res.code == 200) {

                    form.val('requirePlanProductInfoFrom', res.data === undefined ? null : res.data);

                    for (const resKey in res.data.requirePlanItermVOList) {
                        planItemData.push(res.data.requirePlanItermVOList[resKey]);
                    }

                    table.reload('requirePlanProductTable', {
                        data: planItemData
                    })
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            })
        }

        laydate.render({
            elem: '#planReceiveTime'
            , type: 'datetime'
        });



        admin.getDictList("materialTypeId", "pro_customer_product_material",tempData.materialTypeId , "物料类型");




    });
</script>